# -*- coding:utf-8 -*-
# /app.py   主应用文件

from flask import * # 引入Flask
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

from exts import * # 引入数据库
import config # 引入配置文件

#引入蓝图
from views.fronted import fronted
from views.admin import admin
from views.api import api


# 初始化应用对象、数据库
app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)


#注册蓝图
app.register_blueprint(fronted, url_prefix = "/")
app.register_blueprint(admin, url_prefix = "/admin")
app.register_blueprint(api, url_prefix = "/api")


@app.errorhandler(404)
def err_404(err):
    return render_template("err_404.html"), 404


#运行时开启服务器
if __name__ == "__main__":
    # app.run()
    http_server = HTTPServer(WSGIContainer(app))
    http_server.listen(config.server_port)
    IOLoop.instance().start()
